package cn.itcast.hotel;

import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.HotelDoc;
import cn.itcast.hotel.service.IHotelService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.util.List;

/**
 * @author mrchen
 * @date 2022/2/16 14:32
 */
@SpringBootTest
public class HotelCRUDDemo {
    @Autowired
    IHotelService iHotelService;


    @Test
    public void demo(){
//        QueryWrapper<Hotel> wrapper = new QueryWrapper<>();
//        // select * from hotel where city = 杭州 and and
//        wrapper.eq("city","杭州");

        LambdaQueryWrapper<Hotel> wrapper1 = new LambdaQueryWrapper<>();
        wrapper1.eq(Hotel::getCity,"上海");
        wrapper1.eq(Hotel::getBrand,"如家");
        wrapper1.gt(Hotel::getScore,35);
        wrapper1.orderByAsc(Hotel::getPrice);
//        List<Hotel> list = iHotelService.list(wrapper1);
//        list.forEach(System.out::println);
        IPage<Hotel> page = new Page<>(2,5);
        iHotelService.page(page,wrapper1);

        System.out.println("总数量: " + page.getTotal());
        System.out.println("集合数据: " + page.getRecords());
    }
}
